package request

import (
	"Godzilla/enum/fileds"
	"Godzilla/models"
	"reflect"
)

// User 分页参数
type User struct {
	Page 			int64 				`json:"page"`
	Size 			int64				`json:"size"`
	Name 			string				`json:"name"`
	Sort            string              `json:"sort"`
	SortFile        string              `json:"sortFile"`
}

// ValidateUserSort 检验sort字段正序还是倒序
func ValidateUserSort(sort string) bool {
	var validFiled = []string{fileds.ASC, fileds.DESC}
	for _, v := range validFiled{
		if v == sort {
			return true
		}
	}
	return false
}

// ValidateUserSortFile 检验字段是否在结构体中
func ValidateUserSortFile(filed string) bool {
	user := &models.User{}
	ele := reflect.TypeOf(user).Elem()
	for i := 0; i< ele.NumField(); i++ {
		if ele.Field(i).Tag.Get("json") == filed {
			return true
		}
	}
	return false
}